package com.wishwall.web.filters;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 
 * @author yavor.gologanov
 *
 */
public abstract class AbstractFilter implements Filter {

	private Filter nextFilter = null;
	

	@Override
	public void init(FilterConfig config) throws ServletException {
	}
	
	@Override
	public void destroy() {
	}

	@Override
	public abstract void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
			throws IOException, ServletException;
	

	/**
	 * 
	 * @param request
	 * @param response
	 * @param chain
	 * @throws IOException
	 * @throws ServletException
	 */
	public void doNextFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
			throws IOException, ServletException {
		
		if (nextFilter != null) {
			nextFilter.doFilter(request, response, chain);
		} else {
			chain.doFilter(request, response);
		}
		
	}	

	/**
	 * 
	 * @param nextFilter
	 */
	public void setNextFilter(Filter nextFilter) {
		this.nextFilter = nextFilter;
	}
	
}
